<template>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle>
        
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
      <!--历史记录-->
    <historyModal @register="registerHistoryModal"></historyModal>
      <!--表单详情-->
  <itemSpModal @register="registerModal" @success="reload"></itemSpModal>

  </template>
  
  <script lang="ts" name="system-dsApply" setup>
    //ts语法
    import { ref, computed, unref } from 'vue';
    import { BasicTable, TableAction } from '/src/components/Table';
    import { useModal } from '/src/components/Modal';
    import { useMessage } from '/src/hooks/web/useMessage';
    import { columns, searchFormSchema } from './runApply.data';
    import { list,deleteProcessIns,updateInsStatus } from './runApply.api';
    import { useListPage } from '/@/hooks/system/useListPage';
    import historyModal from '../myApply/components/historyModal.vue';
    import itemSpModal from '../dsApply/components/itemSpModal.vue';
    const [registerHistoryModal, {openModal:historyOpenModal}] = useModal();
    const [registerModal, {openModal:addOpenModal}] = useModal();
    const { createMessage } = useMessage();
    //字典model
    // const [registerModal, { openModal }] = useModal();
  
    // 列表页面公共参数、方法
    const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
      designScope: 'dict-template',
      tableProps: {
        title: '进行中的流程',
        api: list,
        columns: columns,
        formConfig: {
          schemas: searchFormSchema,
        },
        actionColumn: {
          width: 300,
          fixed:'right'
        },
      },
      //update-begin---author:wangshuai ---date:20220616  for：[issues/I5AMDD]导入/导出功能，操作后提示没有传递 export.url/import.url 参数------------
      // exportConfig: {
      //   name: '数据字典列表',
      //   url: getExportUrl,
      // },
      // importConfig: {
      //   url: getImportUrl,
      // },
      //update-end---author:wangshuai ---date:20220616  for：[issues/I5AMDD]导入/导出功能，操作后提示没有传递 export.url/import.url 参数--------------
    });
  
    //注册table数据
    const [registerTable, { reload, updateTableDataRecord }, { rowSelection, selectedRowKeys }] = tableContext;
  
    /**
     * 详情
     */
    // async function handleDetail(record) {
    //   openModal(true, {
    //     record,
    //     isUpdate: true,
    //   });
    // }
    /**
     * 删除事件
     */
    async function handleDelete(record) {
      await deleteProcessIns({ ids: record.id,reason:"删除不需要理由"}, reload);
    }
    /**
     * 批量删除事件
     */
    async function batchHandleDelete() {
      // await batchDeleteDict({ ids: selectedRowKeys.value }, reload);
    }
    /**
     * 成功回调
     */
    function handleSuccess() {
      // if (isUpdate) {
      //   updateTableDataRecord(values.id, values);
      // } else {
        console.log("回掉更新！")
        reload();
      // }
    }

    //查看进度
    function handleHistory(record: Recordable){
      historyOpenModal(true, {
        record,
        isUpdate: true,
        showFooter: false,
      });
    }
    //表单数据
    function handleDetail(record: Recordable){
      addOpenModal(true, {
        record,
        isUpdate: true,
        showFooter: false,
      });
    }
      //挂起 激活
      async function handleEditStatus(record: Recordable){
        await updateInsStatus({status:record.status,id:record.id},reload);
    }
    /**
     * 操作栏
     */
    function getTableAction(record) {
      let arrActionList=[];
      if(record.isSuspended){
        record.status=1;
        arrActionList.push({label: '激活', popConfirm:  {title: '是否确认激活',confirm:handleEditStatus.bind(null, record), }})
      }else{
        record.status=0;
        arrActionList.push( {label: '挂起',popConfirm: {title: '是否确认挂起',confirm: handleEditStatus.bind(null, record), }})
      }
        arrActionList.push( {label: '表单数据',onClick: handleDetail.bind(null, record)},)
        arrActionList.push( {label: '审批历史',onClick: handleHistory.bind(null, record)},)
        arrActionList.push( {label: '删除', popConfirm: {title: '是否确认删除',confirm: handleDelete.bind(null, record), }})
      return arrActionList;
      // return [
      //   {
      //     label: '编辑',
      //     onClick: handleEdit.bind(null, record),
      //   },
      //   {
      //     label: '删除',
      //     popConfirm: {
      //       title: '确定删除吗?',
      //       confirm: handleDelete.bind(null, record),
      //     },
      //   },
      // ];
    }
  </script>
  
  <style scoped>

  </style>
  